package com.jinyu.jyly.ui.mine.recharge;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.jinyu.jyly.R;
import com.jinyu.jyly.base.BaseActivity;
import com.jinyu.jyly.bean.AllInfoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 充值
 */
public class RechargeMoneyActivity extends BaseActivity<RechargeMoneyPresenter> implements RechargeMoneyContract.View, ViewPager.OnPageChangeListener {

    @BindView(R.id.fake_status_bar)
    View fakeStatusBar;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.rl_title_view)
    RelativeLayout rlTitleView;
    @BindView(R.id.ll_weichat)
    LinearLayout llWeichat;
    @BindView(R.id.ll_ali)
    LinearLayout llAli;
    @BindView(R.id.viewpager)
    ViewPager viewpager;
    @BindView(R.id.line_weichat)
    View lineWeichat;
    @BindView(R.id.line_ali)
    View lineAli;
    @BindView(R.id.ll_bank)
    LinearLayout ll_bank;
    @BindView(R.id.line_bank)
    View line_bank;

    private RechargeMoneyPresenter presenter;

    @Override
    public int getLayout() {
        return R.layout.activity_recharge_money;
    }

    @Override
    protected RechargeMoneyPresenter getPresenter() {
        if (presenter == null) {
            presenter = new RechargeMoneyPresenter(this, this);
        }
        return presenter;
    }

    @Override
    protected void initEventAndData() {
        QMUIStatusBarHelper.translucent(this);
        QMUIStatusBarHelper.setStatusBarDarkMode(this);
        initViewpager();

    }

    private void initViewpager() {
        ArrayList<String> mlist = new ArrayList<>();
        for (int i = 0; i <= 2; i++) {
            mlist.add("dd");
        }
        MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager(), mlist);
        viewpager.setOffscreenPageLimit(mlist.size());
        viewpager.setAdapter(myPagerAdapter);
        viewpager.addOnPageChangeListener(this);
    }

    @OnClick({R.id.iv_back, R.id.ll_weichat, R.id.ll_ali, R.id.ll_bank, R.id.line_bank})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.ll_weichat:
                viewpager.setCurrentItem(0);
                lineWeichat.setVisibility(View.VISIBLE);
                lineAli.setVisibility(View.GONE);
                line_bank.setVisibility(View.GONE);
                break;
            case R.id.ll_ali:
                viewpager.setCurrentItem(1);
                lineWeichat.setVisibility(View.GONE);
                lineAli.setVisibility(View.VISIBLE);
                line_bank.setVisibility(View.GONE);
                break;
            case R.id.ll_bank:
                //银行
                viewpager.setCurrentItem(2);
                lineWeichat.setVisibility(View.GONE);
                lineAli.setVisibility(View.GONE);
                line_bank.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        switch (position) {
            case 0:
                lineWeichat.setVisibility(View.VISIBLE);
                lineAli.setVisibility(View.GONE);
                line_bank.setVisibility(View.GONE);
                break;
            case 1:
                lineWeichat.setVisibility(View.GONE);
                lineAli.setVisibility(View.VISIBLE);
                line_bank.setVisibility(View.GONE);
                break;
            case 2:
                lineWeichat.setVisibility(View.GONE);
                lineAli.setVisibility(View.GONE);
                line_bank.setVisibility(View.VISIBLE);
                break;
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }

    @Override
    public void onFailer(Throwable throwable) {

    }

    @Override
    public void onUpdataImg(AllInfoBean infoBean) {

    }

    @Override
    public void onAddChong(AllInfoBean infoBean) {

    }

    @Override
    public void getChonePayment(AllInfoBean infoBean) {

    }

    class MyPagerAdapter extends FragmentPagerAdapter {
        private List<String> mDataList;

        public MyPagerAdapter(FragmentManager fm, List<String> dataList) {
            super(fm);
            this.mDataList = dataList;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return "";
        }

        @Override
        public Fragment getItem(int position) {
            if (position == 0) {
                return RechargeMoneyTabFragment.newInstance("weichat");//mUser_score
            } else if(position == 1){
                return RechargeMoneyTabFragment.newInstance("ali");//mUser_score
            }else{
                return RechargeMoneyBankTabFragment.newInstance("bank");
            }
        }

        @Override
        public int getCount() {
            return 3;
        }
    }


}
